import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import FluentUI
import "qrc:/global"
import "qrc:/component"

FluWindow {

    id:login_window
    modality: Qt.ApplicationModal
    title:Lang.login
    width: 340
    height: 400
    appBar: undefined
    fixSize: true
    minimumWidth: 340
    maximumWidth: 340
    minimumHeight: 400
    maximumHeight: 400

    property var mainWindowRegister: registerForWindowResult("/")

    FluAppBar {
        id:app_bar
        title:"CoHub"
        anchors
        {
            top: parent.top
            left: parent.left
            right: parent.right
        }
        closeClickListener: ()=>{FluApp.exit(0)}
    }

    Component.onCompleted:
    {
        textbox_account.focus = true
    }

    Shortcut
    {
        sequence: "return"
        context: Qt.WindowShortcut
        onActivated:
        {
            button_login.onClicked()
        }
    }

    Shortcut
    {
        sequence: "enter"
        context: Qt.WindowShortcut
        onActivated:
        {
            button_login.onClicked()
        }
    }

    Image{
        id:image_logo
        source: "qrc:/res/image/cohub.ico"
        asynchronous: true
        width: 75
        height: 75
        anchors{
            horizontalCenter: parent.horizontalCenter
            top:parent.top
            topMargin: 80
        }
        fillMode:Image.PreserveAspectCrop
    }

    ColumnLayout{
        anchors{
            left: parent.left
            right: parent.right
            top: parent.top
            topMargin: 190
        }

        FluTextBox{
            id:textbox_account

            placeholderText: "请输入账号"
            Layout.preferredWidth: 260
            Layout.alignment: Qt.AlignHCenter
        }

        FluTextBox{
            id:textbox_password
            Layout.topMargin: 20
            Layout.preferredWidth: 260
            placeholderText: "请输入密码"
            echoMode:TextInput.Password
            Layout.alignment: Qt.AlignHCenter
        }

        FluFilledButton{
            id:button_login
            text:Lang.login
            Layout.alignment: Qt.AlignHCenter
            Layout.topMargin: 30
            implicitHeight: 30
            implicitWidth: 80
            onClicked:
            {
                if(textbox_password.text === ""||textbox_account.text === "")
                {
                    showError("未输入账号或密码")
                    return
                }
                mainWindowRegister.launch({password:textbox_password.text, account:textbox_account.text})
                login_window.close()
            }
        }
    }
}
